package com.fr.report.script.function;

import com.fr.base.FRContext;
import com.fr.base.dav.Env;
import com.fr.base.file.DatasourceManager;
import com.fr.data.core.db.TableProcedure;
import com.fr.data.impl.Connection;
import com.fr.data.impl.DatabaseConnection;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;
import java.util.logging.Level;
import java.util.logging.Logger;

public class TABLES extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if ((paramArrayOfObject.length > 2) || (paramArrayOfObject.length == 0))
      return Primitive.ERROR_NAME;
    String str1 = paramArrayOfObject[0].toString();
    String str2 = null;
    if (paramArrayOfObject.length == 2)
      str2 = paramArrayOfObject[1].toString();
    FArray localFArray = new FArray();
    if (str1 == null)
      return Primitive.NULL;
    Connection localConnection = FRContext.getDatasourceManager().getConnection(str1);
    if ((localConnection == null) || (!(localConnection instanceof DatabaseConnection)))
      return Primitive.NULL;
    DatabaseConnection localDatabaseConnection = (DatabaseConnection)localConnection;
    try
    {
      TableProcedure[] arrayOfTableProcedure = FRContext.getCurrentEnv().getSQLTablesProcedure(localDatabaseConnection, str2);
      int i = 0;
      int j = arrayOfTableProcedure.length;
      while (i < j)
      {
        localFArray.add(arrayOfTableProcedure[i]);
        ++i;
      }
    }
    catch (Exception localException)
    {
      FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
    }
    return localFArray;
  }

  public Function.Type getType()
  {
    return Function.REPORT;
  }

  public String getCN()
  {
    return "TABLEAS(connectionName):返回名为connectionName的数据库中的所有表名。\n示例：\n假设在FRDemo这个数据库中，有3个表：a,b,c;\n那么TABLES(\"FRDemo\")等于[a,b,c].";
  }

  public String getEN()
  {
    return "TABLES(connectionName):returns tables which contain in the database named connectionName.\nExample：\nif one database named FRDemo has three tables:a,b,c.\nthen TABLES(\"FRDemo\") returns [a,b,c].";
  }
}